/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-06 17:08:24
 * @LastEditTime: 2022-06-28 20:34:43
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/service/admin"
)

/**
 * @description: 方法描述：获取用户列表
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func GetUserList(c *gin.Context) {
	var listquery common.UserList

	if err := c.BindQuery(&listquery); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}

	ul := admin.AdminUserService.GetUserList(listquery)

	common.ResponseListToJson(http.StatusOK, ul.Page, ul.PerPage, ul.Total, ul.Data, c)
}

/**
 * @description: 方法描述：设置用户状态
 * @Author: maxyang
 * @return {*}
 * @param {*gin.Context} c
 */
func SetUserStatus(c *gin.Context) {
	var userstatus common.UserStatus
	if err := c.ShouldBind(&userstatus); err != nil {
		common.ResponseToJson(http.StatusOK, common.ParamError, err.Error(), c)
		return
	}
	err := admin.AdminUserService.SetUserStatus(userstatus.Id, userstatus.Status)
	if err != nil {
		common.ResponseToJson(http.StatusOK, common.Fail, err.Error(), c)
		return
	}

	common.ResponseToJson(http.StatusOK, common.Ok, "操作成功", c)
}
